﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using PeekService;

namespace PeekWebApp.handler
{
    /// <summary>
    /// ForgetPaswordHandler 的摘要说明
    /// </summary>
    public class ForgetPaswordHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string user = context.Server.UrlDecode(context.Request["user"]);
            UserRegistry u = new UserRegistryService().GetAll().Find(o => o.Email.Equals(user) || o.UserName.Equals(user));
            if (u != null)
            {                     
                string url="尊敬的<b color='red'>"+u.UserName+":</b><br>&nbsp;&nbsp;您好,请您点击以下链接重置密码,谢谢！<br/>http://" + CommonConfig.SiteAlias+"/resetpassword.html?u="+u.UserName+"&p="+u.Code;
                CommonService.SendEmail(u.Email, url,"http://"+CommonConfig.SiteAlias+"密码重置通知，请查收！",SendType.Sys);              
                context.Response.Write("1");
            }
            else
            {
                context.Response.Write("0");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}